﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using STT.Business;
using System.Web.Services;
using System.Data;
using STT.Layer.Connection;

namespace STT.Admin
{
    public partial class Default : System.Web.UI.Page
    {
        public Control kh;
        public string kt;
        ToolBox tb = new ToolBox();
        string Quyen = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            //try
            //{
                if (Request.Cookies["userInfo"] != null)
                {
                    LoadSessionByCookies();
                }
                if (Session["QuyenDN"] != null && Session["TenDN"] != null)
                {
                    if (Request.QueryString["idpage"] == null)
                    {
                        Response.Redirect("~/Admin/Default.aspx?idpage=1");
                    }
                    else
                    {

                        tbChucNang = BTbChucNang.LayChucNangTheoQuyen(Session["QuyenDN"].ToString());
                        kt = Request.QueryString["idpage"].ToString().Trim();
                        HtmlGenericControl gel = new HtmlGenericControl("div");
                        if (kt == "1")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTrangChu.ascx");
                            }
                        }
                        else if (kt == "qlbc")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDNQuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucBangCap.ascx");
                            }
                        }
                        else if (kt == "qlnnl")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDNQuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucNhomNgachLuong.ascx");
                            }
                        }
                        else if (kt == "qlkhc")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "itkb")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemTKB.ascx");
                            }
                        }
                        else if (kt == "qltcv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucCongViec.ascx");
                            }
                        }
                        else if (kt == "qltkb")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTKB.ascx");
                            }
                        }
                        else if (kt == "itt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemTinTuc.ascx");
                            }
                        }
                        else if (kt == "tkhm")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "qlttc")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTinTuc.ascx");
                            }
                        }
                        else if (kt == "tkhv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTimKiemHocVien.ascx");
                            }
                        }
                        else if (kt == "tkgv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTimKiemGiangVien.ascx");
                            }
                        }
                        else if (kt == "dmk1303")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/UcDoiMatKhau.ascx");
                            }
                        }
                        else if (kt == "tkkh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTimKiemKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "tkegv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThongKeGiangVien.ascx");
                            }
                        }
                        else if (kt == "tkehv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThongKeHocVien.ascx");
                            }
                        }
                        else if (kt == "tkekh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThongKeKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "qltdcm")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTDChuyenMon.ascx");
                            }
                        }
                        else if (kt == "qlbchv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHocVienBangCap.ascx");
                            }
                        }
                        else if (kt == "qlnnhv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHocVienNgoaiNgu.ascx");
                            }
                        }
                        else if (kt == "kqht")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucBangDiem.ascx");
                            }
                        }
                        else if (kt == "dsgv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucGiangVien.ascx");
                            }
                        }
                        else if (kt == "qlnngv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucGiangVien_NgoaiNgu.ascx");
                            }
                        }
                        else if (kt == "qlnnl")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucNhomNgachLuong.ascx");
                            }
                        }
                        else if (kt == "qllh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucLop.ascx");
                            }
                        }
                        else if (kt == "qlkhgv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucKhoaHocGiangVien.ascx");
                            }
                        }
                        else if (kt == "qlmh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucMonHoc.ascx");
                            }
                        }
                        else if (kt == "qltdhv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTDHocVan.ascx");
                            }
                        }
                        else if (kt == "qlnndt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucNganh.ascx");
                            }
                        }
                        else if (kt == "qldvtv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucDonVi.ascx");
                            }
                        }
                        else if (kt == "qlcv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucChucVu.ascx");
                            }
                        }
                        else if (kt == "qlbc")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucBangCap.ascx");
                            }
                        }
                        else if (kt == "qlnn")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucNgoaiNgu.ascx");
                            }
                        }
                        else if (kt == "qlpb")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucPhongBan.ascx");
                            }
                        }
                        else if (kt == "qlltt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucLoaiTinTuc.ascx");
                            }
                        }
                        else if (kt == "qldshv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHocVien.ascx");
                            }
                        }
                        else if (kt == "tnm")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTinNhanMoi.ascx");
                            }
                        }
                        else if (kt == "itt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemTinTuc.ascx");
                            }
                        }
                        else if (kt == "qlpl2876")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucPhanLop.ascx");
                            }
                        }
                        else if (kt == "qlnd")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQuanLyNguoiDung.ascx");
                            }
                        }
                        else if (kt == "qlpq")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucPhanQuyen.ascx");
                            }
                        }
                        else if (kt == "cn")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucCaNhan.ascx");
                            }
                        }
                        else if (kt == "ndsgv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemGiangVien.ascx");
                            }
                        }
                        else if (kt == "qlph")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucPhongHoc.ascx");
                            }
                        }
                        else if (kt == "qlc")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucCap.ascx");
                            }
                        }
                        else if (kt == "gtn")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucGuiTinNhan.ascx");
                            }
                        }
                        else if (kt == "qltn")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQuanLyTinNhan.ascx");
                            }
                        }
                        else if (kt == "qlq")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQuyen.ascx");
                            }
                        }
                        else if (kt == "tkh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "qlbl")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucBacLuong.ascx");
                            }
                        }
                        else if (kt == "qlhsl")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHeSoLuong.ascx");
                            }
                        }
                        else if (kt == "qldt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucDanToc.ascx");
                            }
                        }
                        else if (kt == "qlhtdt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHinhThucDaoTao.ascx");
                            }
                        }
                        else if (kt == "qlkv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQLKhuVuc.ascx");
                            }
                        }
                        else if (kt == "qlmnl")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQLMNLuong.ascx");
                            }
                        }
                        else if (kt == "qlhsbll")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucHSBLLuong.ascx");
                            }
                        }
                        else if (kt == "qllk")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucQLLuongKhoan.ascx");
                            }
                        }
                        else if (kt == "ndshv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemHocVien.ascx");
                            }
                        }
                        else if (kt == "tmkh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemKhoaHoc.ascx");
                            }
                        }
                        else if (kt == "ttkb")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemTKB.ascx");
                            }
                        }
                        else if (kt == "qltdvh")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTDHocVan.ascx");
                            }
                        }

                        else if (kt == "thv")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucThemHocVien.ascx");
                            }
                        }
                        else if (kt == "tkedvthgia")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucDonViThamGiaGiangDay.ascx");
                            }
                        }
                        else if (kt == "hvnt")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucTbHocVien_NoiTru.ascx");
                            }
                        }
                        else if (kt == "bdd")
                        {
                            if (Session["TenDN"] == null && Session["QuyenDN"] == null)
                            {
                                Response.Redirect("~/Admin/login.aspx");
                            }
                            else if (Session["TenDN"] != null && Session["QuyenDN"] != null)
                            {

                                PlaceHolder.Controls.Clear();
                                kh = Page.LoadControl("UserControls/ucDiemDanh.ascx");
                            }
                        }
                        gel.Controls.Add(kh);
                        PlaceHolder.Controls.Add(gel);
                    }
                }
                else
                {
                    Response.Redirect("~/Admin/login.aspx");
                }
            //}
            
            //catch {
            //    Response.Redirect("~/Admin/login.aspx");
            //}
        }

        protected void lbtnthoat_Click(object sender, EventArgs e)
        {
            Session["QuyenDN"] = null;
            Session["Anh"] = null;
            Session["TenDN"] = null;
            Response.Cookies["userInfo"].Expires = DateTime.Now.AddDays(-1);
            Response.Redirect("~/Admin/login.aspx");
        }
        private void LoadSessionByCookies()
        {
            DataTable dt = tb.GetDataTableById2("[GetTkDangNhapByTenDN]", Server.HtmlDecode(Request.Cookies["userInfo"]["userName"]));
            DataTable admin = tb.GetDataTableById2("GiangVien_GetByMaDN", Server.HtmlDecode(Request.Cookies["userInfo"]["userName"]));
            Session["QuyenDN"] = dt.Rows[0]["Quyen"].ToString().Trim();
            Session["name"] = dt.Rows[0]["TenDN"].ToString().Trim();
            Session["TenDN"] = dt.Rows[0]["TenDN"].ToString().Trim();
            Session["Anh"] = admin.Rows[0]["Anh"].ToString().Trim();

            //Response.Redirect("~/Admin/Default.aspx?idpage=1");
        }
        //WebMethods

        [WebMethod]
        public static string LayThongTinHocVien(string MaHocVien)
        {
            return BTbHocVien.SelectByID((MaHocVien)).GetXml();
        }

        [WebMethod]
        public static string LayThongTinGiangVien(string MaGiangVien)
        {
            return BTbGiangVien.SelectByID(MaGiangVien).GetXml();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //Xác nhận điều khiển HtmlForm tại thời gian chạy ASP.NET
        }
        DataTable tbChucNang;
        public void MenuDong(string MaCNCha)
        {
            DataTable table = new DataTable();
            table = BTbChucNang.SelectByMaCNCha(MaCNCha);
            int count = table.Rows.Count;

            if (count > 0 && MaCNCha != "0")
                Response.Write("<i class='icon-chevron-down'></i><ul>");

            for (int i = 0; i < count; i++)
            {
                bool test = false;

                for (int j = 0; j < tbChucNang.Rows.Count; j++)
                {
                    if (table.Rows[i]["MaCN"].ToString() == tbChucNang.Rows[j][0].ToString())
                    {
                        test = true;
                        break;
                    }
                }

                if (!test) continue;
                if (MaCNCha != "0")
                    Response.Write("<li><a href='Default.aspx?idpage=" + table.Rows[i]["Link"].ToString() + "'>" + table.Rows[i]["TenCN"].ToString() + "</a>");
                else
                    Response.Write("<li><a href='#'><i class='" + table.Rows[i]["Anh"].ToString() + "'></i><span>" + table.Rows[i]["TenCN"].ToString() + "</span></a>");
                MenuDong(table.Rows[i]["MaCN"].ToString());
            }

            if (count > 0) Response.Write("</ul></li>");
            else Response.Write("</li>");
        }
    }
}